<!doctype html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <link href="images/5.icon" rel="icon" type="image/x-icon"/>
    <title>腾飞健康主页</title>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css">
    <link rel="stylesheet" href="css/index.css">
</head>
<body>
<!--顶部-->
<div class="top pt-1">
    <div class="container">
        <div class="row">
            <div class="col">
                <div class="d-flex justify-content-start " id="nowDate" style="text-align: center"></div>
            </div>
            <div class="col">
                <div class="d-flex justify-content-end">
                    <a href="/baozhuzhongxin"><span style="line-height: 48px">帮助中心</span></a>
                    <a href="/guanyuwomen"><span class="ml-5" style="line-height: 48px">关于我们</span></a>
                </div>
            </div>
        </div>
    </div>
</div>
<!--头部-->
<div class="header mt-2">
    <div class="container">
        <div class="position-relative">
            <div class="logo d-inline-block">
                <img src="images/logo.jpg" alt="logo">
            </div>
            <form class="form-inline search">
                <input class="form-control mr-sm-2" type="search" placeholder="请输入体检医院或体检套餐" aria-label="Search"
                       style="width: 400px">
                <button class="btn btn-outline-primary my-2 my-sm-0" type="submit">搜索</button>
            </form>
        </div>
        <div class="headerNav">
            <a href="#" style="background-color: #1CA4E5; color: white;">首页</a>
            <a href="/taocan" target="_self">体检套餐</a>
            <a href="/yiyuan" target="_self">体检医院</a>
        </div>
    </div>
</div>
<!--轮播-->
<div class="above mt-3">
    <div class="container position-relative">
        <div class="slide">
            <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
                <ol class="carousel-indicators">
                    <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
                    <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
                    <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
                </ol>
                <div class="carousel-inner">
                    <div class="carousel-item active">
                        <img src="images/1.jpg" class="d-block w-100" alt="...">
                    </div>
                    <div class="carousel-item">
                        <img src="images/2.jpg" class="d-block w-100" alt="...">
                    </div>
                    <div class="carousel-item">
                        <img src="images/3.jpg" class="d-block w-100" alt="...">
                    </div>
                </div>
            </div>
        </div>
        <div class="navList">
            <ul class="clearfix" style="height: 400px;width: 200px">
                <li><a href="yiyuan.html"><img src="images/yiyuan.png" alt="体检医院" target="_blank">体检医院</a></li>
                <li><a href="taocan.html"><img src="images/tijian.png" alt="体检套餐" target="_blank">体检套餐</a></li>
                <li><a href="taocan.html"><img src="images/quanbu.png" alt="全身体检" target="_blank">全身体检</a></li>
                <li><a href="taocan.html"><img src="images/changgui.png" alt="常规体检" target="_blank">常规体检</a></li>
            </ul>
        </div>
        <div class="login">
            <div style="text-align: center" class="mt-3">
                <img src="images/user.png" alt="user">
                <div class="mt-2" style="font-size: 12px;color: #acacac" id="userName">请先注册/登录账户</div>
            </div>
            <!--登录注册-->


            <div class="mt-5" id="toLoad" style="display: block;"><!--登录成功后将id=toLoad的div属性设为隐藏-->
                <div style="text-align: center">
                    <button type="button" class="btn btn-outline-primary" style="width: 150px" id="load"
                            data-toggle="modal" data-target="#exampleModalCenter">登录
                    </button>
                </div>
                <div class="mt-3" style="text-align: center">
                    <a href="register.html" target="_blank">
                        <button type="button" class="btn btn-outline-primary" style="width: 150px">注册</button>
                    </a>
                </div>
            </div>
            <!--信息管理-->
            <div class="mt-5" id="message" style="display: none">
                <div style="text-align: center">
                    <a href="/userdingdan">个人中心</a>
                    <div class="mt-3"><a href="#" id="logout">退出登录</a></div>
                </div>

            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle"
     aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalCenterTitle">用户登录</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form class="clearfix">
                    <div class="form-group row">
                        <label for="count" class="col-sm-2 col-form-label" style="text-align: right">帐号</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="count" placeholder="请输入账户" name="userIdentity">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="userPassword" class="col-sm-2 col-form-label" style="text-align: right">密码</label>
                        <div class="col-sm-10">
                            <input type="password" class="form-control" id="userPassword" placeholder="请输入密码"
                                   name="password">
                        </div>
                    </div>
                    <div class="row">
                        <label for="code_input" class="col-sm-2 col-form-label" style="text-align: right">验证码</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control d-inline-block" id="code_input" placeholder="请输入验证码"
                                   style="width: 50%">
                            <div id="v_container" class="d-inline-block ml-3"></div>
                        </div>
                    </div>
                    <button type="submit" class="btn btn-primary float-right" id="loadBtn" style="width: 100px">登录
                    </button>
                </form>
            </div>
        </div>
    </div>
</div>
<input hidden type="text" id="loginStatus" th:value="${session.login}">

<script src="node_modules/jquery/dist/jquery.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.js"></script>
<script src="js/index.js"></script>
<script src="js/gVerify.js"></script>
<script>
    $(window).on("load", function () {
        getDate();
        setInterval(getDate, 1000);
    });
</script>
<script>
    var verifyCode = new GVerify("v_container");
    let login=$("#loginStatus").val();
    $("document").ready(function () {
        if(login){
            $("#toLoad").css("display", "none");
            $("#message").css("display", "block");
        }else{
            $("#toLoad").css("display", "block");
            $("#message").css("display", "none");
        }
    });
    $("#loadBtn").on("click", function () {
        var res = verifyCode.validate(document.getElementById("code_input").value);
        if (res) {
            console.log("登录");
            let userIdentity = $("input[name=userIdentity]").val();
            let password = $("input[name=password]").val();
            console.log(userIdentity + "\t" + password);
            $.ajax({
                url: "/userLogin",
                dataType: "json",
                type: "post",
                data: "userIdentity=" + userIdentity + "&password=" + password,
                success: function (responseResult) {
                    if (responseResult.code == 1) {
                        //window.location.href="/index";
                        $("#toLoad").css("display", "none");
                        $("#message").css("display", "block");
                        alert("登录成功");
                        login=true;

                    } else {
                        alert(responseResult.msg);
                        return false;
                    }
                },
                error: function () {
                    console.log("登录请求失败");
                    alert("登录请求失败");
                    return false;
                }
            })
        } else {
            alert("验证码错误");
            return false;
        }
        return false;
    });

    $("#logout").on("click", function () {
        $.ajax({
            url: "/logout",
            dataType: "json",
            type: "get",
            success: function (result) {
                if (result) {
                    $("#toLoad").css("display", "block");
                    $("#message").css("display", "none");
                    alert("退出成功");
                    login=false;
                } else {
                    alert("退出失败");
                }
            },
            error: function () {
                alert("服务器错误");
            },
        });
    });
</script>
<div class="foot">
    <p align="center">
        版权所有 腾飞健康</p>
</div>
</body>
</html>
